package sskj.regulatory.data.repository

import io.armcha.ribble.domain.repository.SiteVideoRepository
import io.reactivex.Flowable
import io.reactivex.functions.Function
import sskj.regulatory.data.cache.MemoryCache
import sskj.regulatory.data.mapper.Mapper
import sskj.regulatory.data.network.SiteVideoApiService
import sskj.regulatory.data.response.camera.CameraEngResponse
import sskj.regulatory.domain.entity.sitevideo.Site
import sskj.regulatory.domain.fetcher.result_listener.RequestType


open class SiteVideoDataRepository(private var siteVideoApiService: SiteVideoApiService,
                                   private val memoryCache: MemoryCache,
                                   private val mapper: Mapper) : SiteVideoRepository {
    override fun getSiteVideoList(pageCount: Int, page: Int): Flowable<List<Site>> {

//        return if (memoryCache.hasCacheFor(RequestType.SITEVIDEO)) {
//            Flowable.fromCallable<List<Site>> { memoryCache.getCacheForType(RequestType.SITEVIDEO) }
//        } else {
//            siteVideoApiService.getSite(pageCount, page)
//                    .map { mapper.translate(it) }
//                    .doOnNext { memoryCache.put(RequestType.SITEVIDEO, it) }
//        }

        return siteVideoApiService.getSite(pageCount, page).flatMap(Function {
            Flowable.fromCallable<List<Site>> { mapper.translate(it.data) }
        })
    }

}